// 专门处理权限路由的模块
import { constantRoutes, asyncRoutes } from '@/router'
const state = {
  // 一开始 肯定拥有静态路由的权限
  routes: constantRoutes // 路由表  表示 当前用户所拥有的所有路由的数组
}
const mutations = {

  setRoutes(state, newRoutes) {
    state.routes = [...constantRoutes, ...newRoutes]
  }
}
const actions = {

  filterRoutes(context, menus) {
    const routes = []

    menus.forEach(key => {
      routes.push(...asyncRoutes.filter(item => item.name === key))
    })

    context.commit('setRoutes', routes) // 将动态路由提交给mutations
    return routes
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
